﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>点检保养计划</title>
    <link href="//unpkg.com/layui@2.9.17/dist/css/layui.css" rel="stylesheet">
</head>
<body>
    <form class="layui-form layui-row">
        <div class="layui-col-md4">
            <div class="layui-input-wrap">
                <label class="layui-form-label">计划名称：</label>
                <input type="text" style="width:170px" id="RecptName" value="" placeholder="请输入入库单名称" class="layui-input" lay-affix="clear">
            </div>
        </div>
        <div class="layui-col-md4">
            <div class="layui-input-wrap">
                <label class="layui-form-label">计划编号：</label>
                <input type="text" style="width:170px" id="RecptCode" value="" placeholder="请输入入库单编号" class="layui-input" lay-affix="clear">
            </div>
        </div>
        <div class="layui-col-md4">
            <div class="layui-input-wrap">
                <label class="layui-form-label">计划类型： </label>
                <div class="layui-input-block" style="width:180px" >
                    <select id="type" lay-filter="aihao" placeholder="请选择计划类型">
                        <option value="" selected></option>
                        <option value="设备点检计划">设备点检计划</option>
                        <option value="设备保养计划">设备保养计划</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-col-md4">
            <div class="layui-input-wrap">
                <label class="layui-form-label">状态： </label>
                <div class="layui-input-block" style="width:180px">
                    <select id="type" lay-filter="aihao" placeholder="请选择状态">
                        <option value="" selected></option>
                        <option value="草稿">草稿</option>
                        <option value="已确定">已确定</option>
                        <option value="审批中">审批中</option>
                        <option value="已审批">已审批</option>
                        <option value="已完成">已完成</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-btn-container ">
            <button class="layui-btn" lay-submit lay-filter="demo-table-search">查询</button>
            <button type="reset" class="layui-btn layui-btn-primary">清空</button>
            <button type="button" class="layui-btn layui-btn-primary layui-bg-blue" id="addData"> 添加</button>
        </div>
    </form>
    <table class="layui-hide" id="test"></table>
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="//unpkg.com/layui@2.9.17/dist/layui.js"></script>
    <script>
        layui.use(function () {
            var table = layui.table;
            var layer = layui.layer;
            var form = layui.form;
            var table = layui.table;
             var laydate = layui.laydate;
            //显示
            function show() {
                table.render({
                    elem: '#test',
                    url: '/Song/GetWmItemRecptList',
                    //maxHeight: '530px',
                    //toolbar: '#TPL-treeTable-demo',
                     page: true, //开启分页
                     limit: 10,
                     limits: [10, 20, 50, 100],
                    cols: [[
                        { field: 'recptCode', title: '计划编码', width: 150, fixed: 'left' },
                        { field: 'recptName', title: '计划名称', width: 120 },
                        { field: 'vendorName', title: '计划类型', width: 150 },
                        {
                            field: 'recptDate', title: '开始日期', width: 150, templet: function (row) {
                                if (row.recptDate == null) {
                                    return "";
                                }
                                else {
                                    var tmp = row.recptDate.split("T")[0];
                                    return tmp;
                                }
                            }
                        },
                        {
                            field: 'recptDate', title: '结束日期', width: 150, templet: function (row) {
                                if (row.recptDate == null) {
                                    return "";
                                }
                                else {
                                    var tmp = row.recptDate.split("T")[0];
                                    return tmp;
                                }
                            }
                        },
                        { field: 'poCode', title: '频率', width: 150 },
                        {
                            field: 'status', title: '状态', width: 140, templet: function (row) {
                                var tmp = row.status == 'PREPARE' ? "草稿" : "已完成";
                                return tmp;
                            }
                        },
                        {
                            fixed: "right", title: "操作", width: 180, align: "center", templet: function (row) {
                                if (row.status == 'PREPARE') {
                                    var tmp = '<a class="layui-btn layui-btn-xs layui-bg-blue" lay-event="detail">查看</a>';
                                    tmp += '<a class="layui-btn layui-btn-xs layui-bg-red" lay-event="delChild">删除</a>';
                                }else{
                                    var tmp = '';
                                }

                                return tmp;
                            }
                        }
                    ]],
                });
            }
            // 日期
            laydate.render({
                elem: '#recptDate'
            });
            show();//初始化显示
            // 搜索提交
            form.on('submit(demo-table-search)', function (data) {
                var recptname = $("#RecptName").val();    //分类名称
                var vendorname = $("#VendorName").val();    //是否启用
                var recptcode = $("#RecptCode").val();
                var pocode = $("#PoCode").val();
                var recptDate = $("#recptDate").val();
                // 执行搜索重载
                table.reload('test', {
                    page: {
                        curr: 1 // 重新从第 1 页开始
                    },
                    where: {
                        recptname: recptname,
                        vendorname: vendorname,
                        recptcode: recptcode,
                        pocode: pocode,
                        recptDate: recptDate,
                    }// 搜索的字段
                });
                return false; // 阻止默认 form 跳转
            });

                // 添加分类
                    $("#addData").click(function () {
                      layer.open({
                        type: 2,
                    title: '添加物料入库单',
                         shadeClose: true, // 点击遮罩区域，关闭弹层
                          scrollbar: false, // 暂时屏蔽浏览器滚动条
                        skin: 'layui-layer-rim', //加上边框
                        area: ['90%', '90%'], //宽高
                    content: '/Song/AddWmItemRecpt',
                        end: function () {
                            show();//刷新父级页面列表方法，类似于回调函数
                        }
                    });
                    });

            // 单元格工具事件
            table.on('tool(test)', function (obj) {
                var layEvent = obj.event; // 获得 lay-event 对应的值
                var trData = obj.data;
                if (layEvent === "detail") {
                    var data = obj.data;//获取表单中的点击按钮的那一行数据

                    areaCode = data.areaCode;
                    areaId = data.areaId;
                    areaName = data.areaName;
                    charger = data.charger;
                    createTime = data.createTime;
                    id = data.id;
                    iqcCode = data.iqcCode;
                    iqcId = data.iqcId;
                    locationCode = data.locationCode;
                    locationId = data.locationId;
                    locationName = data.locationName;
                    poCode = data.poCode;
                    recptCode = data.recptCode;
                    recptDate = data.recptDate;
                    recptName = data.recptName;
                    remark = data.remark;
                    status = data.status;
                    updateBy = data.updateBy;
                    updateTime = data.updateTime;
                    vendorCode = data.vendorCode;
                    vendorId = data.vendorId;
                    vendorName = data.vendorName;
                    vendorNick = data.vendorNick;
                    warehouseCode = data.warehouseCode;
                    warehouseId = data.warehouseId;
                    warehouseName = data.warehouseName;
                    layer.open({
                        title: '修改物料入库单',
                        skin: 'layui-layer-rim', //加上边框
                        type: 2,
                         shadeClose: true, // 点击遮罩区域，关闭弹层
                          scrollbar: false, // 暂时屏蔽浏览器滚动条
                        area: ['80%', '80%'],
                        content: '/Song/UpdWmItemRecpt',
                        end: function () {
                            show();
                        }
                    });
                }  else if (layEvent === "delChild") {
                    layer.confirm("确定要删除吗？", function (data) {
                        var id = { id: trData.id };
                        // 此处可执行 Ajax 等操作
                        $.post('/Song/DeleteWmItemRecpt', id, function (res) {
                            if (res) {
                                layer.msg("删除成功", { icon: 1, time: 1000 }, function () {
                                    obj.del();
                                    // 刷新表格
                                    table.reload('test');
                                });
                            } else {
                                layer.msg("删除失败", { icon: 2, time: 1000 });
                            }
                        });
                    });
                }
            });
        });
    </script>
</body>
</html>